package com.macro.mall.portal.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.portal.domain.CommentDetail;
import com.macro.mall.portal.domain.CommentDto;
import com.macro.mall.portal.service.UmsCommentService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：Minxiao-Hao
 * @Description: 商品评论管理
 * @name：UmsCommentController
 * @Date：2024/10/26 13:50
 */
@RestController
@RequestMapping("/comment")
@Validated
@Slf4j
public class UmsCommentController {
    @Autowired
    private UmsCommentService umsCommentService;

    /**
     * 添加商品评论接口
     * @param commentDto 评论请求对象
     * @return 成功条数
     */
    @Operation(summary = "添加商品评论接口")
    @PostMapping("/addComment")
    public CommonResult  addComment(@RequestBody CommentDto commentDto){
        // 记录开始时间
        long startTime = System.currentTimeMillis();
        umsCommentService.addComment(commentDto);

        return CommonResult.successMessage("评论成功");
    }
    /**
     * 评论列表接口
     * @param productId 商品id
     * @return 评论列表
     */
    @Operation(summary = "评论列表接口")
    @GetMapping("/list/{productId}")
    public CommonResult<List<CommentDetail>> list(@PathVariable Long productId){
       List<CommentDetail> list=umsCommentService.list(productId);
        return CommonResult.success(list);
    }
}
